package com.htgraph.demo;

import com.ht.impl.shape.ShapeRegister;
import com.htgraph.contour.*;
import com.mxgraph.swing.mxGraphComponent;
import com.mxgraph.view.mxGraph;

import javax.swing.*;
import java.io.FileNotFoundException;

/**
 * Created by IntelliJ IDEA.
 *
 * @author Dong Shufeng
 *         Date: 2010-6-22
 */
public class ContourDemo extends JFrame {

    /**
     *
     */
    private static final long serialVersionUID = -2707712944901661771L;

    public ContourDemo() throws FileNotFoundException {
        super("Hello, World!");

        mxGraph graph = new mxGraph();

        DataPoint[] data = new DataPoint[] {
                new DataPoint(99, 9, 0.97),
                new DataPoint(19, 59, 1.05),
                new DataPoint(179, 59, 1.00),
                new DataPoint(19, 169, 0.96),
                new DataPoint(159, 169, 1.03),
                new DataPoint(99, 189, 0.96)

//                new DataPoint(30, 50, 1.02),
//
//                new DataPoint(150, 150, 1.04),
////                new DataPoint(200, 200,0.99),
//                new DataPoint(170, 50, 0.96)
        };
//        DataPoint[] data = new DataPoint[6];
//        for(int i = 0; i < data.length; i++) {
//            data[i] = new DataPoint(Math.random() * 199, Math.random() * 199, 1.0 + 0.04 *( 1 - 2 * Math.random()));
//        }
        graph.getModel().beginUpdate();
        try {
            for (DataPoint p : data)
                insertVertext(graph, p);
        } finally {
            graph.getModel().endUpdate();
        }
        AbstractContourRenderer renderer = new ContourRenderer_JGraph(graph);
//        renderer.setAlg(new DefaultInterp(800, 800));
//        renderer.setAlg(new InterpGridgroup(100, 100));
        renderer.setAlg(new InterpGridgroup(100, 100));
        renderer.setColorMaker(new ColorMap(2048, ColorMap.MODE_0));
        renderer.setValues(data);
        renderer.buildGraph();

        mxGraphComponent graphComponent = new mxGraphComponent(graph);
        graphComponent.setZoomFactor(1.0);
        getContentPane().add(graphComponent);
    }

    public void insertVertext(mxGraph graph, DataPoint c) {
        graph.insertVertex(graph.getDefaultParent(), null, null, c.getX() - 2, c.getY() - 2, 4, 4, "shape=ellipse");
    }

    public static void main(String[] args) throws FileNotFoundException {
        ShapeRegister.register();
        ContourDemo frame = new ContourDemo();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 320);
        frame.setVisible(true);
    }
}
